N=int(input())
win,equal,lose=0,0,0
A={'B':0,'C':0,'J':0}
B={'B':0,'C':0,'J':0}
for i in range(N):
    info=input()
    if info in ('B C','C J','J B'):
        win+=1
        A[info[0]]+=1
    elif info[0] == info[-1]:
        equal+=1
    else:
        lose+=1
        B[info[-1]]+=1
line1=f'{win} {equal} {lose}'
line2=line1[::-1]
line3=f'{max(A,key=lambda x:A[x])} {max(B,key=lambda x:B[x])}'
print(f'{line1}\n{line2}\n{line3}')
